package com.parenting.feigncontroller;


import com.parenting.entities.SystemResourcesDO;
import com.parenting.feign.controller.IFeignSystemPlatformUserController;
import com.parenting.model.PlatformUserDTO;
import com.parenting.service.PlatformUserService;
import com.parenting.service.SystemResourcesService;
import com.parenting.service.SystemUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class FeignSystemPlatformUserController implements IFeignSystemPlatformUserController {

     @Autowired
     private PlatformUserService platformUserService;

     @Override
     public PlatformUserDTO getParentUserByAccount(String account) {
          PlatformUserDTO platformUserDtoByPlatformUserAccount = platformUserService.getPlatformUserDtoByPlatformUserAccount(account);
          return platformUserDtoByPlatformUserAccount;
     }
     @Autowired
     private SystemUserService systemUserService;
     @Autowired
     private SystemResourcesService systemResourcesService;

     @Override
     public void permissionInitialization(String userId){
          List<SystemResourcesDO> systemResourcesDOS = systemResourcesService.getBaseMapper().selectList(null);
          List<String> ids=new ArrayList<>();
          for (SystemResourcesDO s : systemResourcesDOS){
               ids.add(s.getId());
          }
          systemUserService.saveUserAndResources(userId,ids);
     }

}
